﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WPF_GUI.AirportSVC;
using System.Collections.ObjectModel;
using WPF_GUI.Commanding;
using System.Windows.Input;

namespace WPF_GUI.ViewModels
{
    public class LoadScenarioWindowViewModel : ChildWindowViewModel
    {
        private List<Scenario> _scenarios;
        private Scenario _selectedScenario;

        #region Fields
        
        // Commands
        RelayCommand _okButtonCommand;
        RelayCommand _cancelButtonCommand;

        #endregion

        public LoadScenarioWindowViewModel(MainPageViewModel parentViewModel)
            : base (parentViewModel)
        {
            if (!IsDesignTime)
            {
                _scenarios = parentViewModel.AirportScenarios;
                CanClickOK = true;
                CanClickCancel = true;
            }
        }

        #region Buttons
        #region Button Enablers

        private bool CanClickOK { get; set; }
        private bool CanClickCancel { get; set; }

        #endregion

        #region Button Command Properties

        public ICommand ClickOKCommand
        {
            get
            {
                if (_okButtonCommand == null)
                {
                    _okButtonCommand = new RelayCommand(
                        param => this.ButtonOK_Click(),
                        param => this.CanClickOK
                        );
                }
                return _okButtonCommand;
            }
        }

        public ICommand ClickCancelCommand
        {
            get
            {
                if (_cancelButtonCommand == null)
                {
                    _cancelButtonCommand = new RelayCommand(
                        param => this.ButtonCancel_Click(),
                        param => this.CanClickCancel
                        );
                }
                return _cancelButtonCommand;
            }
        }

        #endregion // Button Command Properties

        #region Button Command Handlers

        public void ButtonOK_Click()
        {
            _parentViewModel.LoadScenario(_selectedScenario.ScenarioId);
            OnRequestClose(); // Request to close this window
        }

        public void ButtonCancel_Click()
        {
            OnRequestClose(); // Request to close this window
        }

        #endregion // Button Command Handlers

        #endregion

        #region Properties

        public List<Scenario> Scenarios
        {
            get
            {
                return _scenarios;
            }

            set
            {
                if (_scenarios != value)
                {
                    _scenarios = value;
                }
            }
        }

        public Scenario SelectedScenario
        {
            get
            {
                return _selectedScenario;
            }

            set
            {
                if (_selectedScenario != value)
                {
                    _selectedScenario = value;
                    OnPropertyChanged("SelectedScenario");
                }
            }
        }

        #endregion
    }
}
